<?php

class PurchaseOrderController extends GxController {

    public function filters() {
        return array('rights');
    }

    public function actionView($id) {
        $this->render('view', array(
            'model' => $this->loadModel($id, 'PurchaseOrder'),
        ));
    }

//    public function actionAdmin() {
//        $model = new PurchaseOrder('search');
//        $model->unsetAttributes();
//        if (isset($_GET['PurchaseOrder']))
//            $model->setAttributes($_GET['PurchaseOrder']);
//
//        $this->render('admin', array(
//            'model' => $model,
//        ));
//    }

    public function actionAdmin() {
        $model = new PurchaseOrder('search');
        $model->unsetAttributes(); 
        if (isset($_GET['PurchaseOrder'])) {
             $model->setAttributes($_GET['PurchaseOrder']);  
        }
        if (isset($_GET['export'])) {
           $production = 'export';            
            $coulmn = array(
                array(
                    'name' => 'users_id',
                    'value' => 'PurchaseOrder::getUsersName($data->users_id)',
                    'filter' => FALSE
                ),
                array(
                    'header' => 'Gift a class',
                    'value' => 'GifttofriendWorkshop::giftClassTousers($data->id)',
                    'filter' => FALSE
                ),
                'transaction_id',
                'order_date_time',
                array(
                    'name' => 'order_confirmed',
                    'type' => 'raw',
                    'value' => '($data->order_confirmed!=0)?"Yes":"No"',
                    'filter' => array('0' => Yii::t('app', 'No'), '1' => Yii::t('app', 'Yes')),
                ),
                'total_price',
            );
        } else {
            $production = 'grid';
            $coulmn = array(
                array(
                    'name' => 'users_id',
                    'value' => 'PurchaseOrder::getUsersName($data->users_id)',
                    'filter' => FALSE
                ),
                array(
                    'header' => 'Gift a class',
                    'value' => 'GifttofriendWorkshop::giftClassTousers($data->id)',
                    'filter' => FALSE
                ),
                'transaction_id',
                'total_price',
                'order_date_time',
                array(
                    'name' => 'order_confirmed',
                    'type' => 'raw',
                    'value' => '($data->order_confirmed!=0)?"Yes":"No"',
                    'filter' => array('0' => Yii::t('app', 'No'), '1' => Yii::t('app', 'Yes')),
                ),
                array(
                    'class' => 'CButtonColumn',
                    'template' => '{view}',
                )
            );
           
        }
       
        $this->render('admin', array('model' => $model, 'production' => $production, 'coulmn' => $coulmn));
    }

}